package test.util;

import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

/**
 * 远程调用工具类
 *
 * @Author piaoransheng
 * @Date 2021/12/7 0:49
 */
public class RemoteCallUtil {
    public static String get(String url) {
        try {
            URL urlObject = new URL(url);
            //开连接
            URLConnection urlConnection = urlObject.openConnection();
            InputStream inputStream = urlConnection.getInputStream();
            byte[] byteArray = new byte[1024];
            int len;
            StringBuilder stringBuilder = new StringBuilder();
            while ((len = inputStream.read(byteArray)) != -1) {
                stringBuilder.append(new String(byteArray, 0, len));
            }
            return stringBuilder.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}